Bullet Collision Detection & Physics Library
btSoftBody.h
Go to the documentation of this file.
1/*
2Bullet Continuous Collision Detection and Physics Library
3Copyright (c) 2003-2006 Erwin Coumans https://bulletphysics.org
4
5This software is provided 'as-is', without any express or implied warranty.
6In no event will the authors be held liable for any damages arising from the use of this software.
7Permission is granted to anyone to use this software for any purpose,
8including commercial applications, and to alter it and redistribute it freely,
9subject to the following restrictions:
10
111. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
122. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
133. This notice may not be removed or altered from any source distribution.
14*/
16
17#ifndef _BT_SOFT_BODY_H
18#define _BT_SOFT_BODY_H
19
25
28#include "btSparseSDF.h"
32//#ifdef BT_USE_DOUBLE_PRECISION
33//#define btRigidBodyData btRigidBodyDoubleData
34//#define btRigidBodyDataName "btRigidBodyDoubleData"
35//#else
36#define btSoftBodyData btSoftBodyFloatData
37#define btSoftBodyDataName "btSoftBodyFloatData"
39static unsigned long seed = 243703;
40//#endif //BT_USE_DOUBLE_PRECISION
41
43class btDispatcher;
45
46/* btSoftBodyWorldInfo */
48{
58
60 : air_density((btScalar)1.2),
62 water_offset(0),
63 m_maxDisplacement(1000.f), //avoid soft body from 'exploding' so use some upper threshold of maximum motion that a node can travel per frame
64 water_normal(0, 0, 0),
65 m_broadphase(0),
66 m_dispatcher(0),
67 m_gravity(0, -10, 0)
68 {
69 }
70};
71
75{
76public:
78
79 // The solver object that handles this soft body
81
82 //
83 // Enumerations
84 //
85
101
103 struct eVSolver
104 {
105 enum _
106 {
109 };
110 };
111
113 struct ePSolver
114 {
123 };
124
136
138 struct eFeature
139 {
149 };
150
153
154 //
155 // Flags
156 //
157
160 {
161 enum _
162 {
163 RVSmask = 0x000f,
164 SDF_RS = 0x0001,
165 CL_RS = 0x0002,
166 SDF_RD = 0x0004,
167
168 SVSmask = 0x00f0,
169 VF_SS = 0x0010,
170 CL_SS = 0x0020,
171 CL_SELF = 0x0040,
172 VF_DD = 0x0080,
173
174 RVDFmask = 0x0f00,
175 SDF_RDF = 0x0100,
176 SDF_MDF = 0x0200,
177 SDF_RDN = 0x0400,
178 /* presets */
181 };
182 };
183
186 {
187 enum _
188 {
189 DebugDraw = 0x0001,
190 /* presets */
193 };
194 };
195
196 //
197 // API Types
198 //
199
200 /* sRayCast */
208
209 /* ImplicitFn */
211 {
212 virtual ~ImplicitFn() {}
213 virtual btScalar Eval(const btVector3& x) = 0;
214 };
215
216 //
217 // Internal types
218 //
219
222
223 /* sCti is Softbody contact info */
224 struct sCti
225 {
226 const btCollisionObject* m_colObj; /* Rigid body */
227 btVector3 m_normal; /* Outward normal */
228 mutable btVector3 m_impulse; /* Applied impulse */
229 btScalar m_offset; /* Offset from origin */
230 btVector3 m_bary; /* Barycentric weights for faces */
231 sCti() : m_impulse(0, 0, 0) {}
232 };
233
234 /* sMedium */
235 struct sMedium
236 {
237 btVector3 m_velocity; /* Velocity */
238 btScalar m_pressure; /* Pressure */
239 btScalar m_density; /* Density */
240 };
241
242 /* Base type */
243 struct Element
244 {
245 void* m_tag; // User data
246 Element() : m_tag(0) {}
247 };
248 /* Material */
250 {
251 btScalar m_kLST; // Linear stiffness coefficient [0,1]
252 btScalar m_kAST; // Area/Angular stiffness coefficient [0,1]
253 btScalar m_kVST; // Volume stiffness coefficient [0,1]
254 int m_flags; // Flags
255 };
256
257 /* Feature */
259 {
260 Material* m_material; // Material
261 };
262 /* Node */
269 struct Node : Feature
270 {
271 btVector3 m_x; // Position
272 btVector3 m_q; // Previous step position/Test position
273 btVector3 m_v; // Velocity
274 btVector3 m_vn; // Previous step velocity
275 btVector3 m_f; // Force accumulator
276 btVector3 m_n; // Normal
277 btScalar m_im; // 1/mass
279 btDbvtNode* m_leaf; // Leaf data
280 int m_constrained; // depth of penetration
281 int m_battach : 1; // Attached
282 int index;
283 btVector3 m_splitv; // velocity associated with split impulse
284 btMatrix3x3 m_effectiveMass; // effective mass in contact
285 btMatrix3x3 m_effectiveMass_inv; // inverse of effective mass
286 };
287 /* Link */
289 Link : Feature
290 {
291 btVector3 m_c3; // gradient
292 Node* m_n[2]; // Node pointers
293 btScalar m_rl; // Rest length
294 int m_bbending : 1; // Bending link
295 btScalar m_c0; // (ima+imb)*kLST
296 btScalar m_c1; // rl^2
297 btScalar m_c2; // |gradient|^2/c0
298
300 };
302 {
303 RenderNode* m_n[3]; // Node pointers
304 };
305
306 /* Face */
307 struct Face : Feature
308 {
309 Node* m_n[3]; // Node pointers
311 btScalar m_ra; // Rest area
312 btDbvtNode* m_leaf; // Leaf data
313 btVector4 m_pcontact; // barycentric weights of the persistent contact
316 };
317 /* Tetra */
318 struct Tetra : Feature
319 {
320 Node* m_n[4]; // Node pointers
321 btScalar m_rv; // Rest volume
322 btDbvtNode* m_leaf; // Leaf data
323 btVector3 m_c0[4]; // gradients
324 btScalar m_c1; // (4*kVST)/(im0+im1+im2+im3)
325 btScalar m_c2; // m_c1/sum(|g0..3|^2)
329 btVector4 m_P_inv[3]; // first three columns of P_inv matrix
330 };
331
332 /* TetraScratch */
334 {
335 btMatrix3x3 m_F; // deformation gradient F
336 btScalar m_trace; // trace of F^T * F
337 btScalar m_J; // det(F)
338 btMatrix3x3 m_cofF; // cofactor of F
339 btMatrix3x3 m_corotation; // corotatio of the tetra
340 };
341
342 /* RContact */
343 struct RContact
344 {
345 sCti m_cti; // Contact infos
346 Node* m_node; // Owner node
347 btMatrix3x3 m_c0; // Impulse matrix
348 btVector3 m_c1; // Relative anchor
349 btScalar m_c2; // ima*dt
350 btScalar m_c3; // Friction
351 btScalar m_c4; // Hardness
352
353 // jacobians and unit impulse responses for multibody
359 };
360
362 {
363 public:
364 sCti m_cti; // Contact infos
365 btMatrix3x3 m_c0; // Impulse matrix
366 btVector3 m_c1; // Relative anchor
367 btScalar m_c2; // inverse mass of node/face
368 btScalar m_c3; // Friction
369 btScalar m_c4; // Hardness
370 btMatrix3x3 m_c5; // inverse effective mass
371
372 // jacobians and unit impulse responses for multibody
378 };
379
381 {
382 public:
383 Node* m_node; // Owner node
384 };
385
387 {
388 public:
389 btVector3 m_local; // Anchor position in body space
390 };
391
393 {
394 public:
395 Face* m_face; // Owner face
396 btVector3 m_contactPoint; // Contact point
397 btVector3 m_bary; // Barycentric weights
398 btVector3 m_weights; // v_contactPoint * m_weights[i] = m_face->m_node[i]->m_v;
399 };
400
402 {
403 Node* m_node; // Node
404 Face* m_face; // Face
405 btVector3 m_bary; // Barycentric weights
406 btVector3 m_weights; // v_contactPoint * m_weights[i] = m_face->m_node[i]->m_v;
409 btScalar m_friction; // Friction
410 btScalar m_imf; // inverse mass of the face at contact point
411 btScalar m_c0; // scale of the impulse matrix;
412 const btCollisionObject* m_colObj; // Collision object to collide with.
413 };
414
415 /* SContact */
416 struct SContact
417 {
418 Node* m_node; // Node
419 Face* m_face; // Face
423 btScalar m_friction; // Friction
424 btScalar m_cfm[2]; // Constraint force mixing
425 };
426 /* Anchor */
427 struct Anchor
428 {
429 Node* m_node; // Node pointer
430 btVector3 m_local; // Anchor position in body space
433 btMatrix3x3 m_c0; // Impulse matrix
434 btVector3 m_c1; // Relative anchor
435 btScalar m_c2; // ima*dt
436 };
437 /* Note */
438 struct Note : Element
439 {
440 const char* m_text; // Text
442 int m_rank; // Rank
443 Node* m_nodes[4]; // Nodes
444 btScalar m_coords[4]; // Coordinates
445 };
446 /* Pose */
447 struct Pose
448 {
449 bool m_bvolume; // Is valid
450 bool m_bframe; // Is frame
451 btScalar m_volume; // Rest volume
452 tVector3Array m_pos; // Reference positions
453 tScalarArray m_wgh; // Weights
455 btMatrix3x3 m_rot; // Rotation
457 btMatrix3x3 m_aqq; // Base scaling
458 };
459 /* Cluster */
491 /* Impulse */
492 struct Impulse
493 {
497 int m_asDrift : 1;
498 Impulse() : m_velocity(0, 0, 0), m_drift(0, 0, 0), m_asVelocity(0), m_asDrift(0) {}
500 {
501 Impulse i = *this;
502 i.m_velocity = -i.m_velocity;
503 i.m_drift = -i.m_drift;
504 return (i);
505 }
507 {
508 Impulse i = *this;
509 i.m_velocity *= x;
510 i.m_drift *= x;
511 return (i);
512 }
513 };
514 /* Body */
515 struct Body
516 {
520
527
528 void activate() const
529 {
530 if (m_rigid)
531 m_rigid->activate();
533 m_collisionObject->activate();
534 }
536 {
537 static const btMatrix3x3 iwi(0, 0, 0, 0, 0, 0, 0, 0, 0);
538 if (m_rigid) return (m_rigid->getInvInertiaTensorWorld());
539 if (m_soft) return (m_soft->m_invwi);
540 return (iwi);
541 }
543 {
544 if (m_rigid) return (m_rigid->getInvMass());
545 if (m_soft) return (m_soft->m_imass);
546 return (0);
547 }
548 const btTransform& xform() const
549 {
550 static const btTransform identity = btTransform::getIdentity();
551 if (m_collisionObject) return (m_collisionObject->getWorldTransform());
552 if (m_soft) return (m_soft->m_framexform);
553 return (identity);
554 }
556 {
557 if (m_rigid) return (m_rigid->getLinearVelocity());
558 if (m_soft) return (m_soft->m_lv);
559 return (btVector3(0, 0, 0));
560 }
562 {
563 if (m_rigid) return (btCross(m_rigid->getAngularVelocity(), rpos));
564 if (m_soft) return (btCross(m_soft->m_av, rpos));
565 return (btVector3(0, 0, 0));
566 }
568 {
569 if (m_rigid) return (m_rigid->getAngularVelocity());
570 if (m_soft) return (m_soft->m_av);
571 return (btVector3(0, 0, 0));
572 }
573 btVector3 velocity(const btVector3& rpos) const
574 {
575 return (linearVelocity() + angularVelocity(rpos));
576 }
577 void applyVImpulse(const btVector3& impulse, const btVector3& rpos) const
578 {
579 if (m_rigid) m_rigid->applyImpulse(impulse, rpos);
580 if (m_soft) btSoftBody::clusterVImpulse(m_soft, rpos, impulse);
581 }
582 void applyDImpulse(const btVector3& impulse, const btVector3& rpos) const
583 {
584 if (m_rigid) m_rigid->applyImpulse(impulse, rpos);
585 if (m_soft) btSoftBody::clusterDImpulse(m_soft, rpos, impulse);
586 }
587 void applyImpulse(const Impulse& impulse, const btVector3& rpos) const
588 {
589 if (impulse.m_asVelocity)
590 {
591 // printf("impulse.m_velocity = %f,%f,%f\n",impulse.m_velocity.getX(),impulse.m_velocity.getY(),impulse.m_velocity.getZ());
592 applyVImpulse(impulse.m_velocity, rpos);
593 }
594 if (impulse.m_asDrift)
595 {
596 // printf("impulse.m_drift = %f,%f,%f\n",impulse.m_drift.getX(),impulse.m_drift.getY(),impulse.m_drift.getZ());
597 applyDImpulse(impulse.m_drift, rpos);
598 }
599 }
600 void applyVAImpulse(const btVector3& impulse) const
601 {
602 if (m_rigid) m_rigid->applyTorqueImpulse(impulse);
604 }
605 void applyDAImpulse(const btVector3& impulse) const
606 {
607 if (m_rigid) m_rigid->applyTorqueImpulse(impulse);
609 }
610 void applyAImpulse(const Impulse& impulse) const
611 {
612 if (impulse.m_asVelocity) applyVAImpulse(impulse.m_velocity);
613 if (impulse.m_asDrift) applyDAImpulse(impulse.m_drift);
614 }
615 void applyDCImpulse(const btVector3& impulse) const
616 {
617 if (m_rigid) m_rigid->applyCentralImpulse(impulse);
619 }
620 };
621 /* Joint */
622 struct Joint
623 {
624 struct eType
625 {
626 enum _
627 {
631 };
632 };
633 struct Specs
634 {
635 Specs() : erp(1), cfm(1), split(1) {}
639 };
649 virtual ~Joint() {}
650 Joint() : m_delete(false) {}
651 virtual void Prepare(btScalar dt, int iterations);
652 virtual void Solve(btScalar dt, btScalar sor) = 0;
653 virtual void Terminate(btScalar dt) = 0;
654 virtual eType::_ Type() const = 0;
655 };
656 /* LJoint */
657 struct LJoint : Joint
658 {
660 {
662 };
664 void Prepare(btScalar dt, int iterations);
665 void Solve(btScalar dt, btScalar sor);
666 void Terminate(btScalar dt);
667 eType::_ Type() const { return (eType::Linear); }
668 };
669 /* AJoint */
670 struct AJoint : Joint
671 {
672 struct IControl
673 {
674 virtual ~IControl() {}
675 virtual void Prepare(AJoint*) {}
676 virtual btScalar Speed(AJoint*, btScalar current) { return (current); }
678 {
679 static IControl def;
680 return (&def);
681 }
682 };
691 void Prepare(btScalar dt, int iterations);
692 void Solve(btScalar dt, btScalar sor);
693 void Terminate(btScalar dt);
694 eType::_ Type() const { return (eType::Angular); }
695 };
696 /* CJoint */
697 struct CJoint : Joint
698 {
704 void Prepare(btScalar dt, int iterations);
705 void Solve(btScalar dt, btScalar sor);
706 void Terminate(btScalar dt);
707 eType::_ Type() const { return (eType::Contact); }
708 };
709 /* Config */
710 struct Config
711 {
712 eAeroModel::_ aeromodel; // Aerodynamic model (default: V_Point)
713 btScalar kVCF; // Velocities correction factor (Baumgarte)
714 btScalar kDP; // Damping coefficient [0,1]
715 btScalar kDG; // Drag coefficient [0,+inf]
716 btScalar kLF; // Lift coefficient [0,+inf]
717 btScalar kPR; // Pressure coefficient [-inf,+inf]
718 btScalar kVC; // Volume conversation coefficient [0,+inf]
719 btScalar kDF; // Dynamic friction coefficient [0,1]
720 btScalar kMT; // Pose matching coefficient [0,1]
721 btScalar kCHR; // Rigid contacts hardness [0,1]
722 btScalar kKHR; // Kinetic contacts hardness [0,1]
723 btScalar kSHR; // Soft contacts hardness [0,1]
724 btScalar kAHR; // Anchors hardness [0,1]
725 btScalar kSRHR_CL; // Soft vs rigid hardness [0,1] (cluster only)
726 btScalar kSKHR_CL; // Soft vs kinetic hardness [0,1] (cluster only)
727 btScalar kSSHR_CL; // Soft vs soft hardness [0,1] (cluster only)
728 btScalar kSR_SPLT_CL; // Soft vs rigid impulse split [0,1] (cluster only)
729 btScalar kSK_SPLT_CL; // Soft vs rigid impulse split [0,1] (cluster only)
730 btScalar kSS_SPLT_CL; // Soft vs rigid impulse split [0,1] (cluster only)
731 btScalar maxvolume; // Maximum volume ratio for pose
732 btScalar timescale; // Time scale
733 int viterations; // Velocities solver iterations
734 int piterations; // Positions solver iterations
735 int diterations; // Drift solver iterations
736 int citerations; // Cluster solver iterations
737 int collisions; // Collisions flags
738 tVSolverArray m_vsequence; // Velocity solvers sequence
739 tPSolverArray m_psequence; // Position solvers sequence
740 tPSolverArray m_dsequence; // Drift solvers sequence
741 btScalar drag; // deformable air drag
742 btScalar m_maxStress; // Maximum principle first Piola stress
743 };
744 /* SolverState */
746 {
747 //if you add new variables, always initialize them!
749 : sdt(0),
750 isdt(0),
751 velmrg(0),
752 radmrg(0),
753 updmrg(0)
754 {
755 }
756 btScalar sdt; // dt*timescale
757 btScalar isdt; // 1/sdt
758 btScalar velmrg; // velocity margin
759 btScalar radmrg; // radial margin
760 btScalar updmrg; // Update margin
761 };
762
764 {
771 RayFromToCaster(const btVector3& rayFrom, const btVector3& rayTo, btScalar mxt);
772 void Process(const btDbvtNode* leaf);
773
774 static /*inline*/ btScalar rayFromToTriangle(const btVector3& rayFrom,
775 const btVector3& rayTo,
776 const btVector3& rayNormalizedDirection,
777 const btVector3& a,
778 const btVector3& b,
779 const btVector3& c,
780 btScalar maxt = SIMD_INFINITY);
781 };
782
783 //
784 // Typedefs
785 //
786
788 typedef void (*vsolver_t)(btSoftBody*, btScalar);
805
806 //
807 // Fields
808 //
809
810 Config m_cfg; // Configuration
811 SolverState m_sst; // Solver state
812 Pose m_pose; // Pose
813 void* m_tag; // User data
826 tRContactArray m_rcontacts; // Rigid contacts
831 tSContactArray m_scontacts; // Soft contacts
834 btScalar m_timeacc; // Time accumulator
835 btVector3 m_bounds[2]; // Spatial bounds
836 bool m_bUpdateRtCst; // Update runtime constants
837 btDbvt m_ndbvt; // Nodes tree
838 btDbvt m_fdbvt; // Faces tree
839 btDbvntNode* m_fdbvnt; // Faces tree with normals
840 btDbvt m_cdbvt; // Clusters tree
842 btScalar m_dampingCoefficient; // Damping Coefficient
845 btAlignedObjectArray<btVector3> m_quads; // quadrature points for collision detection
850
853 btAlignedObjectArray<btScalar> m_z; // vertical distance used in extrapolation
856
857 btAlignedObjectArray<bool> m_clusterConnectivity; //cluster connectivity, for self-collision
858
860
862
863 bool m_reducedModel; // Reduced deformable model flag
864
865 //
866 // Api
867 //
868
869 /* ctor */
870 btSoftBody(btSoftBodyWorldInfo* worldInfo, int node_count, const btVector3* x, const btScalar* m);
871
872 /* ctor */
874
875 void initDefaults();
876
877 /* dtor */
878 virtual ~btSoftBody();
879 /* Check for existing link */
880
882
884 {
885 return m_worldInfo;
886 }
887
888 void setDampingCoefficient(btScalar damping_coeff)
889 {
890 m_dampingCoefficient = damping_coeff;
891 }
892
894 virtual void setCollisionShape(btCollisionShape* collisionShape)
895 {
896 }
897
898 bool checkLink(int node0,
899 int node1) const;
900 bool checkLink(const Node* node0,
901 const Node* node1) const;
902 /* Check for existing face */
903 bool checkFace(int node0,
904 int node1,
905 int node2) const;
906 /* Append material */
907 Material* appendMaterial();
908 /* Append note */
909 void appendNote(const char* text,
910 const btVector3& o,
911 const btVector4& c = btVector4(1, 0, 0, 0),
912 Node* n0 = 0,
913 Node* n1 = 0,
914 Node* n2 = 0,
915 Node* n3 = 0);
916 void appendNote(const char* text,
917 const btVector3& o,
918 Node* feature);
919 void appendNote(const char* text,
920 const btVector3& o,
921 Link* feature);
922 void appendNote(const char* text,
923 const btVector3& o,
924 Face* feature);
925 /* Append node */
926 void appendNode(const btVector3& x, btScalar m);
927 /* Append link */
928 void appendLink(int model = -1, Material* mat = 0);
929 void appendLink(int node0,
930 int node1,
931 Material* mat = 0,
932 bool bcheckexist = false);
933 void appendLink(Node* node0,
934 Node* node1,
935 Material* mat = 0,
936 bool bcheckexist = false);
937 /* Append face */
938 void appendFace(int model = -1, Material* mat = 0);
939 void appendFace(int node0,
940 int node1,
941 int node2,
942 Material* mat = 0);
943 void appendTetra(int model, Material* mat);
944 //
945 void appendTetra(int node0,
946 int node1,
947 int node2,
948 int node3,
949 Material* mat = 0);
950
951 /* Append anchor */
952 void appendDeformableAnchor(int node, btRigidBody* body);
954 void appendAnchor(int node,
955 btRigidBody* body, bool disableCollisionBetweenLinkedBodies = false, btScalar influence = 1);
956 void appendAnchor(int node, btRigidBody* body, const btVector3& localPivot, bool disableCollisionBetweenLinkedBodies = false, btScalar influence = 1);
957 void removeAnchor(int node);
958 /* Append linear joint */
959 void appendLinearJoint(const LJoint::Specs& specs, Cluster* body0, Body body1);
960 void appendLinearJoint(const LJoint::Specs& specs, Body body = Body());
961 void appendLinearJoint(const LJoint::Specs& specs, btSoftBody* body);
962 /* Append linear joint */
963 void appendAngularJoint(const AJoint::Specs& specs, Cluster* body0, Body body1);
964 void appendAngularJoint(const AJoint::Specs& specs, Body body = Body());
965 void appendAngularJoint(const AJoint::Specs& specs, btSoftBody* body);
966 /* Add force (or gravity) to the entire body */
967 void addForce(const btVector3& force);
968 /* Add force (or gravity) to a node of the body */
969 void addForce(const btVector3& force,
970 int node);
971 /* Add aero force to a node of the body */
972 void addAeroForceToNode(const btVector3& windVelocity, int nodeIndex);
973
974 /* Add aero force to a face of the body */
975 void addAeroForceToFace(const btVector3& windVelocity, int faceIndex);
976
977 /* Add velocity to the entire body */
978 void addVelocity(const btVector3& velocity);
979
980 /* Set velocity for the entire body */
981 void setVelocity(const btVector3& velocity);
982
983 /* Add velocity to a node of the body */
984 void addVelocity(const btVector3& velocity,
985 int node);
986 /* Set mass */
987 void setMass(int node,
988 btScalar mass);
989 /* Get mass */
990 btScalar getMass(int node) const;
991 /* Get total mass */
992 btScalar getTotalMass() const;
993 /* Set total mass (weighted by previous masses) */
994 void setTotalMass(btScalar mass,
995 bool fromfaces = false);
996 /* Set total density */
997 void setTotalDensity(btScalar density);
998 /* Set volume mass (using tetrahedrons) */
999 void setVolumeMass(btScalar mass);
1000 /* Set volume density (using tetrahedrons) */
1001 void setVolumeDensity(btScalar density);
1002 /* Get the linear velocity of the center of mass */
1004 /* Set the linear velocity of the center of mass */
1005 void setLinearVelocity(const btVector3& linVel);
1006 /* Set the angular velocity of the center of mass */
1007 void setAngularVelocity(const btVector3& angVel);
1008 /* Get best fit rigid transform */
1010 /* Transform to given pose */
1011 virtual void transformTo(const btTransform& trs);
1012 /* Transform */
1013 virtual void transform(const btTransform& trs);
1014 /* Translate */
1015 virtual void translate(const btVector3& trs);
1016 /* Rotate */
1017 virtual void rotate(const btQuaternion& rot);
1018 /* Scale */
1019 virtual void scale(const btVector3& scl);
1020 /* Get link resting lengths scale */
1022 /* Scale resting length of all springs */
1023 void setRestLengthScale(btScalar restLength);
1024 /* Set current state as pose */
1025 void setPose(bool bvolume,
1026 bool bframe);
1027 /* Set current link lengths as resting lengths */
1028 void resetLinkRestLengths();
1029 /* Return the volume */
1030 btScalar getVolume() const;
1031 /* Cluster count */
1033 {
1034 btVector3 com(0, 0, 0);
1035 for (int i = 0; i < m_nodes.size(); i++)
1036 {
1037 com += (m_nodes[i].m_x * this->getMass(i));
1038 }
1039 com /= this->getTotalMass();
1040 return com;
1041 }
1042 int clusterCount() const;
1043 /* Cluster center of mass */
1044 static btVector3 clusterCom(const Cluster* cluster);
1045 btVector3 clusterCom(int cluster) const;
1046 /* Cluster velocity at rpos */
1047 static btVector3 clusterVelocity(const Cluster* cluster, const btVector3& rpos);
1048 /* Cluster impulse */
1049 static void clusterVImpulse(Cluster* cluster, const btVector3& rpos, const btVector3& impulse);
1050 static void clusterDImpulse(Cluster* cluster, const btVector3& rpos, const btVector3& impulse);
1051 static void clusterImpulse(Cluster* cluster, const btVector3& rpos, const Impulse& impulse);
1052 static void clusterVAImpulse(Cluster* cluster, const btVector3& impulse);
1053 static void clusterDAImpulse(Cluster* cluster, const btVector3& impulse);
1054 static void clusterAImpulse(Cluster* cluster, const Impulse& impulse);
1055 static void clusterDCImpulse(Cluster* cluster, const btVector3& impulse);
1056 /* Generate bending constraints based on distance in the adjency graph */
1057 int generateBendingConstraints(int distance,
1058 Material* mat = 0);
1059 /* Randomize constraints to reduce solver bias */
1060 void randomizeConstraints();
1061
1063
1064 /* Release clusters */
1065 void releaseCluster(int index);
1066 void releaseClusters();
1067 /* Generate clusters (K-mean) */
1070 int generateClusters(int k, int maxiterations = 8192);
1071 /* Refine */
1072 void refine(ImplicitFn* ifn, btScalar accurary, bool cut);
1073 /* CutLink */
1074 bool cutLink(int node0, int node1, btScalar position);
1075 bool cutLink(const Node* node0, const Node* node1, btScalar position);
1076
1078 bool rayTest(const btVector3& rayFrom,
1079 const btVector3& rayTo,
1080 sRayCast& results);
1081 bool rayFaceTest(const btVector3& rayFrom,
1082 const btVector3& rayTo,
1083 sRayCast& results);
1084 int rayFaceTest(const btVector3& rayFrom, const btVector3& rayTo,
1085 btScalar& mint, int& index) const;
1086 /* Solver presets */
1087 void setSolver(eSolverPresets::_ preset);
1088 /* predictMotion */
1089 void predictMotion(btScalar dt);
1090 /* solveConstraints */
1091 void solveConstraints();
1092 /* staticSolve */
1093 void staticSolve(int iterations);
1094 /* solveCommonConstraints */
1095 static void solveCommonConstraints(btSoftBody** bodies, int count, int iterations);
1096 /* solveClusters */
1097 static void solveClusters(const btAlignedObjectArray<btSoftBody*>& bodies);
1098 /* integrateMotion */
1099 void integrateMotion();
1100 /* defaultCollisionHandlers */
1104 bool useSelfCollision();
1105 void updateDeactivation(btScalar timeStep);
1106 void setZeroVelocity();
1107 bool wantsSleeping();
1108
1109 virtual btMatrix3x3 getImpulseFactor(int n_node)
1110 {
1111 btMatrix3x3 tmp;
1112 tmp.setIdentity();
1113 return tmp;
1114 }
1115
1116 //
1117 // Functionality to deal with new accelerated solvers.
1118 //
1119
1123 void setWindVelocity(const btVector3& velocity);
1124
1128 const btVector3& getWindVelocity();
1129
1130 //
1131 // Set the solver that handles this soft body
1132 // Should not be allowed to get out of sync with reality
1133 // Currently called internally on addition to the world
1135 {
1136 m_softBodySolver = softBodySolver;
1137 }
1138
1139 //
1140 // Return the solver that handles this soft body
1141 //
1146
1147 //
1148 // Return the solver that handles this soft body
1149 //
1151 {
1152 return m_softBodySolver;
1153 }
1154
1155 //
1156 // Cast
1157 //
1158
1159 static const btSoftBody* upcast(const btCollisionObject* colObj)
1160 {
1161 if (colObj->getInternalType() == CO_SOFT_BODY)
1162 return (const btSoftBody*)colObj;
1163 return 0;
1164 }
1166 {
1167 if (colObj->getInternalType() == CO_SOFT_BODY)
1168 return (btSoftBody*)colObj;
1169 return 0;
1170 }
1171
1172 //
1173 // ::btCollisionObject
1174 //
1175
1176 virtual void getAabb(btVector3& aabbMin, btVector3& aabbMax) const
1177 {
1178 aabbMin = m_bounds[0];
1179 aabbMax = m_bounds[1];
1180 }
1181 //
1182 // Private
1183 //
1184 void pointersToIndices();
1185 void indicesToPointers(const int* map = 0);
1186
1187 int rayTest(const btVector3& rayFrom, const btVector3& rayTo,
1188 btScalar& mint, eFeature::_& feature, int& index, bool bcountonly) const;
1189 void initializeFaceTree();
1190 void rebuildNodeTree();
1191 btVector3 evaluateCom() const;
1192 bool checkDeformableContact(const btCollisionObjectWrapper* colObjWrap, const btVector3& x, btScalar margin, btSoftBody::sCti& cti, bool predict = false) const;
1193 bool checkDeformableFaceContact(const btCollisionObjectWrapper* colObjWrap, Face& f, btVector3& contact_point, btVector3& bary, btScalar margin, btSoftBody::sCti& cti, bool predict = false) const;
1194 bool checkContact(const btCollisionObjectWrapper* colObjWrap, const btVector3& x, btScalar margin, btSoftBody::sCti& cti) const;
1195 void updateNormals();
1196 void updateBounds();
1197 void updatePose();
1198 void updateConstants();
1199 void updateLinkConstants();
1200 void updateArea(bool averageArea = true);
1201 void initializeClusters();
1202 void updateClusters();
1203 void cleanupClusters();
1204 void prepareClusters(int iterations);
1205 void solveClusters(btScalar sor);
1206 void applyClusters(bool drift);
1207 void dampClusters();
1209 void setGravityFactor(btScalar gravFactor);
1210 void setCacheBarycenter(bool cacheBarycenter);
1211 void initializeDmInverse();
1212 void updateDeformation();
1213 void advanceDeformation();
1214 void applyForces();
1215 void setMaxStress(btScalar maxStress);
1216 void interpolateRenderMesh();
1217 void setCollisionQuadrature(int N);
1218 static void PSolve_Anchors(btSoftBody* psb, btScalar kst, btScalar ti);
1219 static void PSolve_RContacts(btSoftBody* psb, btScalar kst, btScalar ti);
1220 static void PSolve_SContacts(btSoftBody* psb, btScalar, btScalar ti);
1221 static void PSolve_Links(btSoftBody* psb, btScalar kst, btScalar ti);
1222 static void VSolve_Links(btSoftBody* psb, btScalar kst);
1223 static psolver_t getSolver(ePSolver::_ solver);
1224 static vsolver_t getSolver(eVSolver::_ solver);
1226#define SAFE_EPSILON SIMD_EPSILON * 100.0
1227 void updateNode(btDbvtNode* node, bool use_velocity, bool margin)
1228 {
1229 if (node->isleaf())
1230 {
1231 btSoftBody::Node* n = (btSoftBody::Node*)(node->data);
1233 vol;
1234 btScalar pad = margin ? m_sst.radmrg : SAFE_EPSILON; // use user defined margin or margin for floating point precision
1235 if (use_velocity)
1236 {
1237 btVector3 points[2] = {n->m_x, n->m_x + m_sst.sdt * n->m_v};
1238 vol = btDbvtVolume::FromPoints(points, 2);
1239 vol.Expand(btVector3(pad, pad, pad));
1240 }
1241 else
1242 {
1243 vol = btDbvtVolume::FromCR(n->m_x, pad);
1244 }
1245 node->volume = vol;
1246 return;
1247 }
1248 else
1249 {
1250 updateNode(node->childs[0], use_velocity, margin);
1251 updateNode(node->childs[1], use_velocity, margin);
1253 vol;
1254 Merge(node->childs[0]->volume, node->childs[1]->volume, vol);
1255 node->volume = vol;
1256 }
1257 }
1258
1259 void updateNodeTree(bool use_velocity, bool margin)
1260 {
1261 if (m_ndbvt.m_root)
1262 updateNode(m_ndbvt.m_root, use_velocity, margin);
1263 }
1264
1265 template <class DBVTNODE> // btDbvtNode or btDbvntNode
1266 void updateFace(DBVTNODE* node, bool use_velocity, bool margin)
1267 {
1268 if (node->isleaf())
1269 {
1270 btSoftBody::Face* f = (btSoftBody::Face*)(node->data);
1271 btScalar pad = margin ? m_sst.radmrg : SAFE_EPSILON; // use user defined margin or margin for floating point precision
1273 vol;
1274 if (use_velocity)
1275 {
1276 btVector3 points[6] = {f->m_n[0]->m_x, f->m_n[0]->m_x + m_sst.sdt * f->m_n[0]->m_v,
1277 f->m_n[1]->m_x, f->m_n[1]->m_x + m_sst.sdt * f->m_n[1]->m_v,
1278 f->m_n[2]->m_x, f->m_n[2]->m_x + m_sst.sdt * f->m_n[2]->m_v};
1279 vol = btDbvtVolume::FromPoints(points, 6);
1280 }
1281 else
1282 {
1283 btVector3 points[3] = {f->m_n[0]->m_x,
1284 f->m_n[1]->m_x,
1285 f->m_n[2]->m_x};
1286 vol = btDbvtVolume::FromPoints(points, 3);
1287 }
1288 vol.Expand(btVector3(pad, pad, pad));
1289 node->volume = vol;
1290 return;
1291 }
1292 else
1293 {
1294 updateFace(node->childs[0], use_velocity, margin);
1295 updateFace(node->childs[1], use_velocity, margin);
1297 vol;
1298 Merge(node->childs[0]->volume, node->childs[1]->volume, vol);
1299 node->volume = vol;
1300 }
1301 }
1302 void updateFaceTree(bool use_velocity, bool margin)
1303 {
1304 if (m_fdbvt.m_root)
1305 updateFace(m_fdbvt.m_root, use_velocity, margin);
1306 if (m_fdbvnt)
1307 updateFace(m_fdbvnt, use_velocity, margin);
1308 }
1309
1310 template <typename T>
1311 static inline T BaryEval(const T& a,
1312 const T& b,
1313 const T& c,
1314 const btVector3& coord)
1315 {
1316 return (a * coord.x() + b * coord.y() + c * coord.z());
1317 }
1318
1319 void applyRepulsionForce(btScalar timeStep, bool applySpringForce)
1320 {
1322 {
1323 // randomize the order of repulsive force
1324 indices.resize(m_faceNodeContacts.size());
1325 for (int i = 0; i < m_faceNodeContacts.size(); ++i)
1326 indices[i] = i;
1327#define NEXTRAND (seed = (1664525L * seed + 1013904223L) & 0xffffffff)
1328 int i, ni;
1329
1330 for (i = 0, ni = indices.size(); i < ni; ++i)
1331 {
1332 btSwap(indices[i], indices[NEXTRAND % ni]);
1333 }
1334 }
1335 for (int k = 0; k < m_faceNodeContacts.size(); ++k)
1336 {
1337 int idx = indices[k];
1339 btSoftBody::Node* node = c.m_node;
1340 btSoftBody::Face* face = c.m_face;
1341 const btVector3& w = c.m_bary;
1342 const btVector3& n = c.m_normal;
1343 btVector3 l = node->m_x - BaryEval(face->m_n[0]->m_x, face->m_n[1]->m_x, face->m_n[2]->m_x, w);
1344 btScalar d = c.m_margin - n.dot(l);
1345 d = btMax(btScalar(0), d);
1346
1347 const btVector3& va = node->m_v;
1348 btVector3 vb = BaryEval(face->m_n[0]->m_v, face->m_n[1]->m_v, face->m_n[2]->m_v, w);
1349 btVector3 vr = va - vb;
1350 const btScalar vn = btDot(vr, n); // dn < 0 <==> opposing
1351 if (vn > OVERLAP_REDUCTION_FACTOR * d / timeStep)
1352 continue;
1353 btVector3 vt = vr - vn * n;
1354 btScalar I = 0;
1355 btScalar mass = node->m_im == 0 ? 0 : btScalar(1) / node->m_im;
1356 if (applySpringForce)
1357 I = -btMin(m_repulsionStiffness * timeStep * d, mass * (OVERLAP_REDUCTION_FACTOR * d / timeStep - vn));
1358 if (vn < 0)
1359 I += 0.5 * mass * vn;
1360 int face_penetration = 0, node_penetration = node->m_constrained;
1361 for (int i = 0; i < 3; ++i)
1362 face_penetration |= face->m_n[i]->m_constrained;
1363 btScalar I_tilde = 2.0 * I / (1.0 + w.length2());
1364
1365 // double the impulse if node or face is constrained.
1366 if (face_penetration > 0 || node_penetration > 0)
1367 {
1368 I_tilde *= 2.0;
1369 }
1370 if (face_penetration <= 0)
1371 {
1372 for (int j = 0; j < 3; ++j)
1373 face->m_n[j]->m_v += w[j] * n * I_tilde * node->m_im;
1374 }
1375 if (node_penetration <= 0)
1376 {
1377 node->m_v -= I_tilde * node->m_im * n;
1378 }
1379
1380 // apply frictional impulse
1381 btScalar vt_norm = vt.safeNorm();
1382 if (vt_norm > SIMD_EPSILON)
1383 {
1384 btScalar delta_vn = -2 * I * node->m_im;
1385 btScalar mu = c.m_friction;
1386 btScalar vt_new = btMax(btScalar(1) - mu * delta_vn / (vt_norm + SIMD_EPSILON), btScalar(0)) * vt_norm;
1387 I = 0.5 * mass * (vt_norm - vt_new);
1388 vt.safeNormalize();
1389 I_tilde = 2.0 * I / (1.0 + w.length2());
1390 // double the impulse if node or face is constrained.
1391 if (face_penetration > 0 || node_penetration > 0)
1392 I_tilde *= 2.0;
1393 if (face_penetration <= 0)
1394 {
1395 for (int j = 0; j < 3; ++j)
1396 face->m_n[j]->m_v += w[j] * vt * I_tilde * (face->m_n[j])->m_im;
1397 }
1398 if (node_penetration <= 0)
1399 {
1400 node->m_v -= I_tilde * node->m_im * vt;
1401 }
1402 }
1403 }
1404 }
1405 virtual int calculateSerializeBufferSize() const;
1406
1408 virtual const char* serialize(void* dataBuffer, class btSerializer* serializer) const;
1409};
1410
1411#endif //_BT_SOFT_BODY_H
btDbvtAabbMm btDbvtVolume
Definition btDbvt.h:177
DBVT_INLINE void Merge(const btDbvtAabbMm &a, const btDbvtAabbMm &b, btDbvtAabbMm &r)
Definition btDbvt.h:745
const T & btMax(const T &a, const T &b)
Definition btMinMax.h:27
const T & btMin(const T &a, const T &b)
Definition btMinMax.h:21
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition btScalar.h:314
#define ATTRIBUTE_ALIGNED16(a)
Definition btScalar.h:99
#define SIMD_INFINITY
Definition btScalar.h:544
#define SIMD_EPSILON
Definition btScalar.h:543
void btSwap(T &a, T &b)
Definition btScalar.h:643
static unsigned long seed
Definition btSoftBody.h:39
static const btScalar OVERLAP_REDUCTION_FACTOR
Definition btSoftBody.h:38
#define NEXTRAND
#define SAFE_EPSILON
btScalar btDot(const btVector3 &v1, const btVector3 &v2)
Return the dot product between two vectors.
Definition btVector3.h:890
btVector3 btCross(const btVector3 &v1, const btVector3 &v2)
Return the cross product of two vectors.
Definition btVector3.h:918
The btAlignedObjectArray template class uses a subset of the stl::vector interface for its methods It...
int size() const
return the number of elements in the array
void resize(int newsize, const T &fillData=T())
The btBroadphaseInterface class provides an interface to detect aabb-overlapping object pairs.
int getInternalType() const
reserved for Bullet internal usage
The btCollisionShape class provides an interface for collision shapes that can be shared among btColl...
The btDispatcher interface class can be used in combination with broadphase to dispatch calculations ...
The btMatrix3x3 class implements a 3x3 rotation matrix, to perform linear algebra in combination with...
Definition btMatrix3x3.h:50
void setIdentity()
Set the matrix to the identity.
The btQuaternion implements quaternion to perform linear algebra rotations in combination with btMatr...
The btRigidBody is the main class for rigid body objects.
Definition btRigidBody.h:60
static const btRigidBody * upcast(const btCollisionObject *colObj)
to keep collision detection and dynamics separate we don't store a rigidbody pointer but a rigidbody ...
btMultiBodyJacobianData jacobianData_t1
Definition btSoftBody.h:374
btMultiBodyJacobianData jacobianData_normal
Definition btSoftBody.h:373
btMultiBodyJacobianData jacobianData_t2
Definition btSoftBody.h:375
The btSoftBody is an class to simulate cloth and volumetric soft bodies.
Definition btSoftBody.h:75
static void PSolve_Links(btSoftBody *psb, btScalar kst, btScalar ti)
static void PSolve_SContacts(btSoftBody *psb, btScalar, btScalar ti)
bool checkLink(int node0, int node1) const
bool m_bUpdateRtCst
Definition btSoftBody.h:836
btScalar m_sleepingThreshold
Definition btSoftBody.h:843
virtual void transformTo(const btTransform &trs)
btVector3 getLinearVelocity()
bool checkFace(int node0, int node1, int node2) const
void advanceDeformation()
btAlignedObjectArray< eVSolver::_ > tVSolverArray
Definition btSoftBody.h:151
void setGravityFactor(btScalar gravFactor)
void updateClusters()
btDbvt m_cdbvt
Definition btSoftBody.h:840
void setPose(bool bvolume, bool bframe)
bool cutLink(int node0, int node1, btScalar position)
void appendFace(int model=-1, Material *mat=0)
void setMass(int node, btScalar mass)
void interpolateRenderMesh()
tJointArray m_joints
Definition btSoftBody.h:832
btScalar m_dampingCoefficient
Definition btSoftBody.h:842
void updateNode(btDbvtNode *node, bool use_velocity, bool margin)
btAlignedObjectArray< TetraScratch > m_tetraScratchesTn
Definition btSoftBody.h:823
void integrateMotion()
btAlignedObjectArray< Tetra > tTetraArray
Definition btSoftBody.h:797
void rebuildNodeTree()
bool rayFaceTest(const btVector3 &rayFrom, const btVector3 &rayTo, sRayCast &results)
void appendLinearJoint(const LJoint::Specs &specs, Cluster *body0, Body body1)
tRenderFaceArray m_renderFaces
Definition btSoftBody.h:820
btAlignedObjectArray< SContact > tSContactArray
Definition btSoftBody.h:800
virtual void scale(const btVector3 &scl)
btAlignedObjectArray< bool > m_clusterConnectivity
Definition btSoftBody.h:857
void updateFaceTree(bool use_velocity, bool margin)
void defaultCollisionHandler(const btCollisionObjectWrapper *pcoWrap)
btScalar getVolume() const
bool rayTest(const btVector3 &rayFrom, const btVector3 &rayTo, sRayCast &results)
Ray casting using rayFrom and rayTo in worldspace, (not direction!)
SolverState m_sst
Definition btSoftBody.h:811
void addVelocity(const btVector3 &velocity)
btAlignedObjectArray< RContact > tRContactArray
Definition btSoftBody.h:799
void setDampingCoefficient(btScalar damping_coeff)
Definition btSoftBody.h:888
void predictMotion(btScalar dt)
void setSelfCollision(bool useSelfCollision)
void setLinearVelocity(const btVector3 &linVel)
btScalar m_timeacc
Definition btSoftBody.h:834
btAlignedObjectArray< int > m_userIndexMapping
Definition btSoftBody.h:881
btAlignedObjectArray< Face > tFaceArray
Definition btSoftBody.h:795
void appendTetra(int model, Material *mat)
void setRestLengthScale(btScalar restLength)
btDbvntNode * m_fdbvnt
Definition btSoftBody.h:839
void updateNodeTree(bool use_velocity, bool margin)
virtual void rotate(const btQuaternion &rot)
void updateFace(DBVTNODE *node, bool use_velocity, bool margin)
void applyClusters(bool drift)
void setZeroVelocity()
static void PSolve_Anchors(btSoftBody *psb, btScalar kst, btScalar ti)
btAlignedObjectArray< DeformableFaceNodeContact > m_faceNodeContactsCCD
Definition btSoftBody.h:830
btSoftBodyWorldInfo * m_worldInfo
Definition btSoftBody.h:814
void setSoftBodySolver(btSoftBodySolver *softBodySolver)
btAlignedObjectArray< btAlignedObjectArray< btScalar > > tDenseMatrix
Definition btSoftBody.h:804
void updateArea(bool averageArea=true)
void addForce(const btVector3 &force)
bool wantsSleeping()
void prepareClusters(int iterations)
void setCollisionQuadrature(int N)
static void clusterVImpulse(Cluster *cluster, const btVector3 &rpos, const btVector3 &impulse)
virtual const char * serialize(void *dataBuffer, class btSerializer *serializer) const
fills the dataBuffer and returns the struct name (and 0 on failure)
btAlignedObjectArray< DeformableFaceNodeContact > m_faceNodeContacts
Definition btSoftBody.h:828
static void VSolve_Links(btSoftBody *psb, btScalar kst)
tTetraArray m_tetras
Definition btSoftBody.h:821
bool useSelfCollision()
btVector3 evaluateCom() const
void setTotalDensity(btScalar density)
btAlignedObjectArray< const class btCollisionObject * > m_collisionDisabledObjects
Definition btSoftBody.h:77
btAlignedObjectArray< Link > tLinkArray
Definition btSoftBody.h:794
static void clusterDAImpulse(Cluster *cluster, const btVector3 &impulse)
void appendNode(const btVector3 &x, btScalar m)
void staticSolve(int iterations)
void setVolumeMass(btScalar mass)
btScalar m_restLengthScale
Definition btSoftBody.h:861
bool checkDeformableContact(const btCollisionObjectWrapper *colObjWrap, const btVector3 &x, btScalar margin, btSoftBody::sCti &cti, bool predict=false) const
bool m_reducedModel
Definition btSoftBody.h:863
void cleanupClusters()
Config m_cfg
Definition btSoftBody.h:810
void updateDeactivation(btScalar timeStep)
btAlignedObjectArray< TetraScratch > m_tetraScratches
Definition btSoftBody.h:822
const btVector3 & getWindVelocity()
Return the wind velocity for interaction with the air.
void addAeroForceToFace(const btVector3 &windVelocity, int faceIndex)
btAlignedObjectArray< btVector4 > m_renderNodesInterpolationWeights
Definition btSoftBody.h:851
void appendAngularJoint(const AJoint::Specs &specs, Cluster *body0, Body body1)
tFaceArray m_faces
Definition btSoftBody.h:819
void setAngularVelocity(const btVector3 &angVel)
void setVolumeDensity(btScalar density)
static void clusterDCImpulse(Cluster *cluster, const btVector3 &impulse)
virtual void transform(const btTransform &trs)
bool m_softSoftCollision
Definition btSoftBody.h:855
static void clusterVAImpulse(Cluster *cluster, const btVector3 &impulse)
btScalar getMass(int node) const
tMaterialArray m_materials
Definition btSoftBody.h:833
void setMaxStress(btScalar maxStress)
void dampClusters()
btSoftBody(btSoftBodyWorldInfo *worldInfo, int node_count, const btVector3 *x, const btScalar *m)
void updateDeformation()
btAlignedObjectArray< btScalar > m_z
Definition btSoftBody.h:853
void addAeroForceToNode(const btVector3 &windVelocity, int nodeIndex)
void applyRepulsionForce(btScalar timeStep, bool applySpringForce)
btAlignedObjectArray< btVector3 > tVector3Array
Definition btSoftBody.h:221
static btVector3 clusterCom(const Cluster *cluster)
tRContactArray m_rcontacts
Definition btSoftBody.h:826
void appendAnchor(int node, btRigidBody *body, bool disableCollisionBetweenLinkedBodies=false, btScalar influence=1)
btAlignedObjectArray< Node > tNodeArray
Definition btSoftBody.h:791
btVector3 m_bounds[2]
Definition btSoftBody.h:835
btScalar m_maxSpeedSquared
Definition btSoftBody.h:844
void releaseCluster(int index)
btAlignedObjectArray< RenderNode > tRenderNodeArray
Definition btSoftBody.h:792
btScalar m_repulsionStiffness
Definition btSoftBody.h:846
void setVelocity(const btVector3 &velocity)
tClusterArray m_clusters
Definition btSoftBody.h:841
btAlignedObjectArray< Joint * > tJointArray
Definition btSoftBody.h:802
void solveConstraints()
btAlignedObjectArray< DeformableFaceRigidContact > m_faceRigidContacts
Definition btSoftBody.h:829
int generateClusters(int k, int maxiterations=8192)
generateClusters with k=0 will create a convex cluster for each tetrahedron or triangle otherwise an ...
void geometricCollisionHandler(btSoftBody *psb)
void releaseClusters()
void refine(ImplicitFn *ifn, btScalar accurary, bool cut)
void setSolver(eSolverPresets::_ preset)
static T BaryEval(const T &a, const T &b, const T &c, const btVector3 &coord)
Material * appendMaterial()
void removeAnchor(int node)
btAlignedObjectArray< DeformableNodeRigidAnchor > m_deformableAnchors
Definition btSoftBody.h:825
void setCacheBarycenter(bool cacheBarycenter)
btAlignedObjectArray< Material * > tMaterialArray
Definition btSoftBody.h:801
btAlignedObjectArray< Anchor > tAnchorArray
Definition btSoftBody.h:798
btScalar m_gravityFactor
Definition btSoftBody.h:847
static void solveClusters(const btAlignedObjectArray< btSoftBody * > &bodies)
void appendNote(const char *text, const btVector3 &o, const btVector4 &c=btVector4(1, 0, 0, 0), Node *n0=0, Node *n1=0, Node *n2=0, Node *n3=0)
bool checkDeformableFaceContact(const btCollisionObjectWrapper *colObjWrap, Face &f, btVector3 &contact_point, btVector3 &bary, btScalar margin, btSoftBody::sCti &cti, bool predict=false) const
virtual int calculateSerializeBufferSize() const
btAlignedObjectArray< DeformableNodeRigidContact > m_nodeRigidContacts
Definition btSoftBody.h:827
btAlignedObjectArray< btSoftBody * > tSoftBodyArray
Definition btSoftBody.h:803
static void PSolve_RContacts(btSoftBody *psb, btScalar kst, btScalar ti)
virtual btMatrix3x3 getImpulseFactor(int n_node)
static void clusterImpulse(Cluster *cluster, const btVector3 &rpos, const Impulse &impulse)
btAlignedObjectArray< btAlignedObjectArray< const btSoftBody::Node * > > m_renderNodesParents
Definition btSoftBody.h:852
tRenderNodeArray m_renderNodes
Definition btSoftBody.h:817
void pointersToIndices()
tNoteArray m_notes
Definition btSoftBody.h:815
void updateNormals()
static void clusterDImpulse(Cluster *cluster, const btVector3 &rpos, const btVector3 &impulse)
btDbvt m_fdbvt
Definition btSoftBody.h:838
tLinkArray m_links
Definition btSoftBody.h:818
void applyForces()
static btVector3 clusterVelocity(const Cluster *cluster, const btVector3 &rpos)
btTransform getRigidTransform()
tSContactArray m_scontacts
Definition btSoftBody.h:831
bool m_cacheBarycenter
Definition btSoftBody.h:848
bool m_useSelfCollision
Definition btSoftBody.h:854
void * m_tag
Definition btSoftBody.h:813
void updatePose()
btAlignedObjectArray< btDbvtNode * > tLeafArray
Definition btSoftBody.h:793
void(* psolver_t)(btSoftBody *, btScalar, btScalar)
Definition btSoftBody.h:787
void initializeClusters()
btSoftBodyWorldInfo * getWorldInfo()
Definition btSoftBody.h:883
tAnchorArray m_anchors
Definition btSoftBody.h:824
btScalar getRestLengthScale()
btAlignedObjectArray< Note > tNoteArray
Definition btSoftBody.h:790
void updateState(const btAlignedObjectArray< btVector3 > &qs, const btAlignedObjectArray< btVector3 > &vs)
void randomizeConstraints()
virtual void setCollisionShape(btCollisionShape *collisionShape)
Definition btSoftBody.h:894
btVector3 m_windVelocity
Definition btSoftBody.h:859
btScalar getTotalMass() const
tNodeArray m_nodes
Definition btSoftBody.h:816
btAlignedObjectArray< ePSolver::_ > tPSolverArray
Definition btSoftBody.h:152
void appendLink(int model=-1, Material *mat=0)
void setSpringStiffness(btScalar k)
void initializeDmInverse()
static const btSoftBody * upcast(const btCollisionObject *colObj)
void updateConstants()
void setTotalMass(btScalar mass, bool fromfaces=false)
btSoftBodySolver * getSoftBodySolver()
virtual ~btSoftBody()
void appendDeformableAnchor(int node, btRigidBody *body)
btAlignedObjectArray< RenderFace > tRenderFaceArray
Definition btSoftBody.h:796
void updateLinkConstants()
virtual void getAabb(btVector3 &aabbMin, btVector3 &aabbMax) const
void(* vsolver_t)(btSoftBody *, btScalar)
Definition btSoftBody.h:788
void initDefaults()
btAlignedObjectArray< btVector3 > m_quads
Definition btSoftBody.h:845
static psolver_t getSolver(ePSolver::_ solver)
bool checkContact(const btCollisionObjectWrapper *colObjWrap, const btVector3 &x, btScalar margin, btSoftBody::sCti &cti) const
void indicesToPointers(const int *map=0)
static void solveCommonConstraints(btSoftBody **bodies, int count, int iterations)
btAlignedObjectArray< Cluster * > tClusterArray
Definition btSoftBody.h:789
void updateBounds()
void setWindVelocity(const btVector3 &velocity)
Set a wind velocity for interaction with the air.
btSoftBodySolver * getSoftBodySolver() const
int generateBendingConstraints(int distance, Material *mat=0)
btAlignedObjectArray< btVector3 > m_X
Definition btSoftBody.h:849
virtual void translate(const btVector3 &trs)
btVector3 getCenterOfMass() const
void initializeFaceTree()
btSoftBodySolver * m_softBodySolver
Definition btSoftBody.h:80
void resetLinkRestLengths()
int clusterCount() const
btAlignedObjectArray< btScalar > tScalarArray
Definition btSoftBody.h:220
btDbvt m_ndbvt
Definition btSoftBody.h:837
static void clusterAImpulse(Cluster *cluster, const Impulse &impulse)
static btSoftBody * upcast(btCollisionObject *colObj)
The btTransform class supports rigid transforms with only translation and rotation and no scaling/she...
Definition btTransform.h:30
static const btTransform & getIdentity()
Return an identity transform.
btVector3 can be used to represent 3D points and vectors.
Definition btVector3.h:82
btScalar safeNorm() const
Return the norm (length) of the vector.
Definition btVector3.h:269
const btScalar & z() const
Return the z value.
Definition btVector3.h:579
btVector3 & safeNormalize()
Definition btVector3.h:286
btScalar dot(const btVector3 &v) const
Return the dot product.
Definition btVector3.h:229
btScalar length2() const
Return the length of the vector squared.
Definition btVector3.h:251
const btScalar & x() const
Return the x value.
Definition btVector3.h:575
const btScalar & y() const
Return the y value.
Definition btVector3.h:577
static btDbvtAabbMm FromCR(const btVector3 &c, btScalar r)
Definition btDbvt.h:473
static btDbvtAabbMm FromPoints(const btVector3 *pts, int n)
Definition btDbvt.h:488
btDbvtNode * childs[2]
Definition btDbvt.h:187
void * data
Definition btDbvt.h:188
btDbvtVolume volume
Definition btDbvt.h:182
DBVT_INLINE bool isleaf() const
Definition btDbvt.h:184
The btDbvt class implements a fast dynamic bounding volume tree based on axis aligned bounding boxes ...
Definition btDbvt.h:229
btDispatcher * m_dispatcher
Definition btSoftBody.h:55
btScalar water_density
Definition btSoftBody.h:50
btSparseSdf< 3 > m_sparsesdf
Definition btSoftBody.h:57
btVector3 m_gravity
Definition btSoftBody.h:56
btVector3 water_normal
Definition btSoftBody.h:53
btScalar m_maxDisplacement
Definition btSoftBody.h:52
btScalar water_offset
Definition btSoftBody.h:51
btBroadphaseInterface * m_broadphase
Definition btSoftBody.h:54
static IControl * Default()
Definition btSoftBody.h:677
virtual btScalar Speed(AJoint *, btScalar current)
Definition btSoftBody.h:676
virtual void Prepare(AJoint *)
Definition btSoftBody.h:675
btVector3 m_axis[2]
Definition btSoftBody.h:689
void Prepare(btScalar dt, int iterations)
void Solve(btScalar dt, btScalar sor)
IControl * m_icontrol
Definition btSoftBody.h:690
void Terminate(btScalar dt)
eType::_ Type() const
Definition btSoftBody.h:694
btRigidBody * m_body
Definition btSoftBody.h:431
btMatrix3x3 m_c0
Definition btSoftBody.h:433
btScalar invMass() const
Definition btSoftBody.h:542
Body(Cluster *p)
Definition btSoftBody.h:522
const btMatrix3x3 & invWorldInertia() const
Definition btSoftBody.h:535
void applyVImpulse(const btVector3 &impulse, const btVector3 &rpos) const
Definition btSoftBody.h:577
btVector3 angularVelocity() const
Definition btSoftBody.h:567
btRigidBody * m_rigid
Definition btSoftBody.h:518
btVector3 linearVelocity() const
Definition btSoftBody.h:555
btVector3 angularVelocity(const btVector3 &rpos) const
Definition btSoftBody.h:561
void applyDImpulse(const btVector3 &impulse, const btVector3 &rpos) const
Definition btSoftBody.h:582
Body(const btCollisionObject *colObj)
Definition btSoftBody.h:523
btVector3 velocity(const btVector3 &rpos) const
Definition btSoftBody.h:573
void applyDCImpulse(const btVector3 &impulse) const
Definition btSoftBody.h:615
void applyDAImpulse(const btVector3 &impulse) const
Definition btSoftBody.h:605
const btTransform & xform() const
Definition btSoftBody.h:548
void activate() const
Definition btSoftBody.h:528
void applyVAImpulse(const btVector3 &impulse) const
Definition btSoftBody.h:600
Cluster * m_soft
Definition btSoftBody.h:517
void applyAImpulse(const Impulse &impulse) const
Definition btSoftBody.h:610
void applyImpulse(const Impulse &impulse, const btVector3 &rpos) const
Definition btSoftBody.h:587
const btCollisionObject * m_collisionObject
Definition btSoftBody.h:519
void Terminate(btScalar dt)
eType::_ Type() const
Definition btSoftBody.h:707
btVector3 m_rpos[2]
Definition btSoftBody.h:701
void Prepare(btScalar dt, int iterations)
void Solve(btScalar dt, btScalar sor)
btVector3 m_dimpulses[2]
Definition btSoftBody.h:472
tVector3Array m_framerefs
Definition btSoftBody.h:464
btMatrix3x3 m_invwi
Definition btSoftBody.h:469
btScalar m_maxSelfCollisionImpulse
Definition btSoftBody.h:482
btMatrix3x3 m_locii
Definition btSoftBody.h:468
btAlignedObjectArray< Node * > m_nodes
Definition btSoftBody.h:463
btDbvtNode * m_leaf
Definition btSoftBody.h:477
btVector3 m_vimpulses[2]
Definition btSoftBody.h:471
tScalarArray m_masses
Definition btSoftBody.h:462
btScalar m_selfCollisionImpulseFactor
Definition btSoftBody.h:483
btTransform m_framexform
Definition btSoftBody.h:465
tPSolverArray m_psequence
Definition btSoftBody.h:739
tPSolverArray m_dsequence
Definition btSoftBody.h:740
eAeroModel::_ aeromodel
Definition btSoftBody.h:712
tVSolverArray m_vsequence
Definition btSoftBody.h:738
const btCollisionObject * m_colObj
Definition btSoftBody.h:412
btVector4 m_pcontact
Definition btSoftBody.h:313
btVector3 m_normal
Definition btSoftBody.h:310
btDbvtNode * m_leaf
Definition btSoftBody.h:312
Material * m_material
Definition btSoftBody.h:260
virtual btScalar Eval(const btVector3 &x)=0
Impulse operator*(btScalar x) const
Definition btSoftBody.h:506
Impulse operator-() const
Definition btSoftBody.h:499
btVector3 m_drift
Definition btSoftBody.h:645
btVector3 m_sdrift
Definition btSoftBody.h:646
virtual void Solve(btScalar dt, btScalar sor)=0
virtual void Terminate(btScalar dt)=0
btMatrix3x3 m_massmatrix
Definition btSoftBody.h:647
btVector3 m_refs[2]
Definition btSoftBody.h:641
virtual void Prepare(btScalar dt, int iterations)
virtual eType::_ Type() const =0
void Solve(btScalar dt, btScalar sor)
btVector3 m_rpos[2]
Definition btSoftBody.h:663
eType::_ Type() const
Definition btSoftBody.h:667
void Prepare(btScalar dt, int iterations)
void Terminate(btScalar dt)
btVector3 m_splitv
Definition btSoftBody.h:283
btDbvtNode * m_leaf
Definition btSoftBody.h:279
btMatrix3x3 m_effectiveMass_inv
Definition btSoftBody.h:285
btMatrix3x3 m_effectiveMass
Definition btSoftBody.h:284
btScalar m_coords[4]
Definition btSoftBody.h:444
btVector3 m_offset
Definition btSoftBody.h:441
Node * m_nodes[4]
Definition btSoftBody.h:443
const char * m_text
Definition btSoftBody.h:440
btMatrix3x3 m_scl
Definition btSoftBody.h:456
btScalar m_volume
Definition btSoftBody.h:451
btVector3 m_com
Definition btSoftBody.h:454
tVector3Array m_pos
Definition btSoftBody.h:452
btMatrix3x3 m_aqq
Definition btSoftBody.h:457
btMatrix3x3 m_rot
Definition btSoftBody.h:455
tScalarArray m_wgh
Definition btSoftBody.h:453
btMultiBodyJacobianData jacobianData_t2
Definition btSoftBody.h:356
btMultiBodyJacobianData jacobianData_t1
Definition btSoftBody.h:355
btMultiBodyJacobianData jacobianData_normal
Definition btSoftBody.h:354
RayFromToCaster(const btVector3 &rayFrom, const btVector3 &rayTo, btScalar mxt)
void Process(const btDbvtNode *leaf)
static btScalar rayFromToTriangle(const btVector3 &rayFrom, const btVector3 &rayTo, const btVector3 &rayNormalizedDirection, const btVector3 &a, const btVector3 &b, const btVector3 &c, btScalar maxt=SIMD_INFINITY)
RenderNode * m_n[3]
Definition btSoftBody.h:303
btScalar m_element_measure
Definition btSoftBody.h:328
btMatrix3x3 m_Dm_inverse
Definition btSoftBody.h:326
btMatrix3x3 m_F
Definition btSoftBody.h:327
btVector4 m_P_inv[3]
Definition btSoftBody.h:329
btVector3 m_c0[4]
Definition btSoftBody.h:323
btDbvtNode * m_leaf
Definition btSoftBody.h:322
@ V_TwoSided
Vertex normals are oriented toward velocity.
Definition btSoftBody.h:92
@ V_OneSided
Vertex normals are flipped to match velocity and lift and drag forces are applied.
Definition btSoftBody.h:94
@ END
Face normals are taken as it is.
Definition btSoftBody.h:98
@ V_TwoSidedLiftDrag
Vertex normals are flipped to match velocity.
Definition btSoftBody.h:93
@ F_OneSided
Face normals are flipped to match velocity and lift and drag forces are applied.
Definition btSoftBody.h:97
@ F_TwoSided
Vertex normals are taken as it is.
Definition btSoftBody.h:95
@ F_TwoSidedLiftDrag
Face normals are flipped to match velocity.
Definition btSoftBody.h:96
ePSolver : positions solvers
Definition btSoftBody.h:114
@ RContacts
Anchor solver.
Definition btSoftBody.h:119
@ SContacts
Rigid contacts solver.
Definition btSoftBody.h:120
@ Anchors
Linear solver.
Definition btSoftBody.h:118
@ END
Soft contacts solver.
Definition btSoftBody.h:121
eVSolver : velocities solvers
Definition btSoftBody.h:104
@ END
Linear solver.
Definition btSoftBody.h:108
@ SDF_RDN
GJK based Multibody vs. deformable face.
Definition btSoftBody.h:177
@ VF_SS
Rigid versus soft mask.
Definition btSoftBody.h:169
@ Default
SDF based Rigid vs. deformable node.
Definition btSoftBody.h:179
@ RVDFmask
Vertex vs face soft vs soft handling.
Definition btSoftBody.h:174
@ VF_DD
Cluster soft body self collision.
Definition btSoftBody.h:172
@ CL_SS
Vertex vs face soft vs soft handling.
Definition btSoftBody.h:170
@ CL_SELF
Cluster vs cluster soft vs soft handling.
Definition btSoftBody.h:171
@ SVSmask
rigid vs deformable
Definition btSoftBody.h:168
@ SDF_RS
Rigid versus soft mask.
Definition btSoftBody.h:164
@ SDF_RD
Cluster vs convex rigid vs soft.
Definition btSoftBody.h:166
@ SDF_RDF
Rigid versus deformable face mask.
Definition btSoftBody.h:175
@ SDF_MDF
GJK based Rigid vs. deformable face.
Definition btSoftBody.h:176
@ CL_RS
SDF based rigid vs soft.
Definition btSoftBody.h:165
@ Default
Enable debug draw.
Definition btSoftBody.h:191
btVector3 m_impulse
Definition btSoftBody.h:228
const btCollisionObject * m_colObj
Definition btSoftBody.h:226
btVector3 m_bary
Definition btSoftBody.h:230
btScalar m_offset
Definition btSoftBody.h:229
btVector3 m_normal
Definition btSoftBody.h:227
eFeature::_ feature
soft body
Definition btSoftBody.h:204
btScalar fraction
feature index
Definition btSoftBody.h:206
int index
feature type
Definition btSoftBody.h:205
btSoftBody * body
Definition btSoftBody.h:203